def encrypt(str1, key1, width, height, origin):
    str2 = ""
    M1 = [[" " for j in range(width)] for i in range(height)]
    M2 = [[" " for j in range(width)] for i in range(height)]
    for i in range(0, len(str1)):
        M1[i//width][i%width] = str1[i]
    for i in range(0, len(key1)):
        for j in range(0, height):
            M2[j][key1[i] - 1] = M1[j][origin[i] - 1]
    for i in range(0, height):
        for j in range(0, width):
            str2 += M2[i][j]
    print(str2)
    return str2
str1 = "State Key Laboratory"
str1 = str1.replace(" ", "")
origin = [1,2,3,4,5,6]
key1 = [3,6,2,4,1,5]
width = 6
length = len(str1)
height = length // width
if length % width != 0:
    height += 1
str2 = encrypt(str1, key1, width, height, origin)
key2 = [5,3,1,4,6,2]
str3 = encrypt(str2, key2, width, height, origin)